<template>
  <div class="container-set">
<!--    <CodeHeader :title="$route.meta.name"></CodeHeader>-->
    <div class="set-btn">
      <code-button @click="closeCode" round>注销一码通</code-button>
    </div>
  </div>
</template>

<script>
import CodeButton from "@/components/code/Button";
import CodeHeader from "@/components/code/Header";
import config from "../../views/test/config";
import { getSSCApplyInfo, getSSCSign } from "@/apis/test";

export default {
  name: "CodeMineSetting",
  components: {
    CodeButton,
    CodeHeader
  },
  mounted() {
    document.title = "设置";
    console.log("ssss", location.href.split("setting")[0] + "logout");
  },
  methods: {
    closeCode() {
      this.$dialog
        .confirm({
          message: "是否要注销一码通？"
          // showCancelButton: false
        })
        .then(() => {
          this.signInfo();
          // localStorage.clear();
          // sessionStorage.clear();
          // location.href = "yi-code://home";
        })
        .catch(() => {});
    },
    async signInfo() {
      let res = await getSSCApplyInfo();
      if (res.ok) {
        if (res && res.data) {
          this.logout(res.data);
        }
      } else {
        this.$dialog.alert({
          message: res.message
        });
      }
    },
    async logout(data) {
      let url = location.href.split("setting")[0] + "logout";
      let params = {
        channelNo: data.channelNo,
        signNo: data.signNo,
        returnUrl: url,
        isWeb: "1"
      };
      let res = await getSSCSign(params);
      if (res.ok) {
        if (res && res.data) {
          location.href = `${config.sscServer}/indep/cardInfo?${res.data}`;
        }
      } else {
        this.$dialog.alert({
          message: res.message
        });
      }
    }
  }
};
</script>

<style scoped lang="less">
.container-set {
  background: #ffffff;
  /*display: flex;*/
  /*flex-direction: column-reverse;*/
  /*justify-content: space-between;*/

  .set-btn {
    position: absolute;
    top: 50px;
    left: 50%;
    transform: translateX(-50%);
  }
}
</style>
